package com.ly.thread;

import java.util.concurrent.*;

public class ThreadPoolDemo2 {

    public static void main(String[] args) {

        ExecutorService threadPool = new ThreadPoolExecutor(2,5,2L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        ExecutorService threadPool2 = new ThreadPoolExecutor(2,5,2L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(),new ThreadPoolExecutor.CallerRunsPolicy());
        ExecutorService threadPool3 = new ThreadPoolExecutor(2,5,2L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(),new ThreadPoolExecutor.DiscardOldestPolicy());
        ExecutorService threadPool4 = new ThreadPoolExecutor(2,5,2L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(),new ThreadPoolExecutor.DiscardPolicy());

        try{
            for(int i=0;i<10;i++) {
                threadPool4.execute(() -> {
                    System.out.println(Thread.currentThread().getName());
                });
            }
        }catch(Exception e){

        }finally {
            threadPool4.shutdown();
        }

    }
}
